package com.wedo.book.controller;

import com.wedo.book.pojo.BookHot;
import com.wedo.book.service.BookHotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("hot")
public class BookHotController {

    @Autowired
    private BookHotService bookHotService;

    @GetMapping
    public ResponseEntity<BookHot> queryHotByBid(@RequestParam("bid")Long bid) {
        BookHot result = this.bookHotService.queryBookHotByBid(bid);
        if (result == null) {
            return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
        }
        return ResponseEntity.ok(result);
    }

    /**
     * 修改图书热度信息
     * @param bookHot
     * @return
     */
    @PutMapping
    public ResponseEntity<BookHot> updateBookHot(@RequestBody BookHot bookHot) {
        if (bookHot.getbId() == null||bookHot.getbId() < 1) {
            return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
        }
        this.bookHotService.updateBookHot(bookHot);
        return ResponseEntity.ok(bookHot);
    }
}
